$(function(){
	main_person()
	administrative_permission()
	senior()
	coreTheme()
	branchFirm()
});

function main_person(){
	$.ajax({
		url: '/spider-factory/stock/main_person',
		type: 'POST',
		data: {
			firm_id: firm_id,
			page: "1",
			size: "10"
		},
		success: function(res){
			let resObj=JSON.parse(res)
			let list=resObj.list
			let num=1
			if(list.length>0){
				for(const i in list){
					$('#main_person').append(
						'<tr>'+
							'<td>'+num+'</td>'+
							'<td>'+list[i].name+''+(list[i].is_highEnd_consumption_restricted=="0" ? "" : "<span class=\'badge badge-danger\'>被限制高消费</span>")+'</td>'+
							'<td>'+list[i].position+'</td>'+
							'<td><a href="/spider-factory/stock/main_person-detail?article_public_id='+list[i].article_public_id+'&companyName='+stock+'" target="_blank">详情</a></td>'+
						'</tr>'
					)
					num+=1
				}
				if(resObj.totalPage>1){
					$('#main_person').append(
						'<tr>'+
							'<td colspan="4" style="text-align:center;"><a href="/spider-factory/stock/main_person-more?firm_id='+firm_id+'&companyName='+stock+'" target="_blank">查看更多</a></td>'+
						'</tr>'
					)
				}
			}else{
				$('#main_person_show').hide()
				$('#main_person_show').prev().hide()
			}
		},
		error: function(res){
			console.log(res)
		}
	})
}

function administrative_permission(){
	$.ajax({
		url: '/spider-factory/stock/administrative_permission',
		type: 'POST',
		data: {
			firm_id: firm_id,
			page: "1",
			size: "10"
		},
		success: function(res){
			let resObj=JSON.parse(res)
			let list=resObj.list
			let num=1
			if(list.length>0){
				for(const i in list){
					$('#administrative_permission').append(
						'<tr>'+
							'<td>'+num+'</td>'+
							'<td style="width:150px;">'+list[i].license_number+'</td>'+
							'<td>'+list[i].license_name+'</td>'+
							'<td>'+(list[i].validity_from==undefined || list[i].validity_from=="" ? "" : list[i].validity_from.substring(0,10))+'</td>'+
							'<td>'+(list[i].validity_to=="" || list[i].validity_to==undefined ? "" : list[i].validity_to.substring(0,10))+'</td>'+
							'<td>'+list[i].issue_authority+'</td>'+
							'<td style="width:50px;"><a href="/spider-factory/stock/administrative_permission-detail?article_public_id='+list[i].article_public_id+'&companyName='+stock+'" target="_blank">详情</a></td>'+
						'</tr>'
					)
					num+=1
				}
				if(resObj.totalPage>1){
					$('#administrative_permission').append(
						'<tr>'+
							'<td colspan="7" style="text-align:center;"><a href="/spider-factory/stock/administrative_permission-more?firm_id='+firm_id+'&companyName='+stock+'" target="_blank">查看更多</a></td>'+
						'</tr>'
					)
				}
			}else{
				$('#administrative_permission_show').hide()
				$('#administrative_permission_show').prev().hide()
			}
		},
		error: function(res){
			console.log(res)
		}
	})
}

function senior() {
	$.ajax({
		url: '/spider-factory/stock/senior',
		type: 'POST',
		data: {
			firm_id: firm_id,
			page: "1",
			size: "10"
		},
		success: function(res){
			let resObj=JSON.parse(res)
			let list=resObj.list
			console.log(list)
			let num=1
			if(list.length>0){
				for(const i in list){
					$('#senior').append(
						'<tr>'+
							'<td>'+num+'</td>'+
							'<td>'+list[i].name+''+(list[i].is_highEnd_consumption_restricted=="0" ? "" : "<span class=\'badge badge-danger\'>被限制高消费</span>")+'</td>'+
							'<td>'+(list[i].gender=="" ? "" : list[i].gender=="1" ? "男" : "女")+'</td>'+
							'<td>'+list[i].person_age+'</td>'+
							'<td>'+list[i].education_level+'</td>'+
							'<td>'+list[i].position+'</td>'+
							'<td>'+(list[i].validityfrom=="" ? "" : list[i].validityfrom.substring(0,10))+'</td>'+
							'<td><a href="/spider-factory/stock/senior-detail?article_public_id='+list[i].article_public_id+'&companyName='+stock+'" target="_blank">详情</a></td>'+
						'</tr>'
					)
					num+=1
				}
				if(resObj.totalPage>1){
					$('#senior').append(
						'<tr>'+
							'<td colspan="8" style="text-align:center;"><a href="/spider-factory/stock/senior-more?firm_id='+firm_id+'&companyName='+stock+'" target="_blank">查看更多</a></td>'+
						'</tr>'
					)
				}
			}else{
				$('#senior_show').hide()
				$('#senior_show').prev().hide()
			}
		},
		error: function(res){
			console.log(res)
		}
	})
}

function branchFirm() {
	$.ajax({
		url: '/spider-factory/stock/branchFirm',
		type: 'POST',
		data: {
			firm_id: firm_id,
			page: "1",
			size: "10"
		},
		success: function(res){
			let resObj=JSON.parse(res)
			let list=resObj.list
			console.log(list)
			let num=1
			if(list.length>0){
				for(const i in list){
					$('#branchFirm').append(
						'<tr>'+
							'<td>'+num+'</td>'+
							'<td>'+list[i].be_invest_firm_name+'</td>'+
							'<td>'+list[i].be_invest_person_name+'</td>'+
							'<td>'+(list[i].be_invest_firm_establish_time=="" ? "" : list[i].be_invest_firm_establish_time.substring(0,10))+'</td>'+
							'<td>'+(list[i].be_invest_firm_status=="1" ? "开业" : "注销")+'</td>'+
						'</tr>'
					)
					num+=1
				}
				if(resObj.totalPage>1){
					$('#branchFirm').append(
						'<tr>'+
							'<td colspan="5" style="text-align:center;"><a href="/spider-factory/stock/branchFirm-more?firm_id='+firm_id+'&companyName='+stock+'" target="_blank">查看更多</a></td>'+
						'</tr>'
					)
				}
			}else{
				$('#branchFirm_show').hide()
				$('#branchFirm_show').prev().hide()
			}
		},
		error: function(res){
			console.log(res)
		}
	})
}

function coreTheme() {
	$.ajax({
		url: '/spider-factory/stock/issue_info',
		type: 'POST',
		data: {
			firm_id: firm_id,
			page: "1",
			size: "1"
		},
		success: function(res){
			let resObj=JSON.parse(res)
			let list=resObj.list
			if(list.length>0){
					let coreThemeArr=JSON.parse(list[0].coreTopics_text)
					let yd=''
					let ydc=''
					let b=''
					let bc=''
					for(const coreTheme of coreThemeArr){
						yd=coreTheme.substring(0, coreTheme.indexOf(' '))
						ydc=coreTheme.substring(coreTheme.indexOf(' ')+1, coreTheme.length)
						b=' '+ydc.substring(0, ydc.indexOf(' '))
						bc=ydc.substring(ydc.indexOf(' '), ydc.length)
						$('#coreTheme').append(
							'<p>'+yd+'<b>'+b+'</b>'+bc+'</p>'
						)
					}
			}else{
				$('#coreTheme_show').hide()
				$('#coreTheme_show').prev().hide()
			}
		},
		error: function(res){
			console.log(res)
		}
	})
}